from wtforms import StringField, IntegerField
from wtforms.validators import length, DataRequired, NumberRange
from web.control.verification import BaseForm


class QuestionnaireForm(BaseForm):
    questionTitle = StringField(validators=[DataRequired(message="问卷不可空标题"),
                                            length(max=64, message="问卷标题超过最大设定长度")])
    userId = StringField(validators=[DataRequired(message="问卷不可缺少用户id"),
                                     length(max=64, message="用户id超过最大长度")])
    status = IntegerField(validators=[DataRequired(message="问卷状态不能为空"),
                                      NumberRange(max=3, message="问卷状态异常")])


class QuestionForm(BaseForm):
    order = IntegerField(validators=[DataRequired(message="问题序号不能为空"),
                                     NumberRange(max=30, message="问题序号超过最大限定长度，请检查问题数量是否超过最大限定")])
    questionName = StringField(validators=[DataRequired(message="问题描述不可为空"),
                                           length(max=256, message="问题描述超过最大限定长度")])
    questionnaireId = IntegerField(validators=[DataRequired(message="问卷编号不能为空")])
    type = IntegerField(validators=[DataRequired(message="问卷类型不能为空"),
                                    NumberRange(max=3, message="问卷类型异常")])
    required = IntegerField(validators=[DataRequired(message="问题是否必答不能为空"),
                                        NumberRange(min=1, max=2, message="状态异常")])


class OptionsForm(BaseForm):
    optionName = StringField(validators=[DataRequired(message="选项描述不可为空"),
                                         length(max=64, message="选项描述超过最大限定长度")])
    questionId = IntegerField(validators=[DataRequired(message="问题编号不能为空")])
    count = IntegerField(validators=[])


class UserForm(BaseForm):
    userAccount = StringField(validators=[DataRequired(message="账号不可为空"),
                                          length(max=32, message="账号超过限定长度")])
    passWord = StringField(validators=[DataRequired(message="密码不可为空"),
                                       length(max=256, message="密码超过限定长度")])
    root = IntegerField(validators=[DataRequired(message="用户权限不能为空")])


class CompletedForm(BaseForm):
    userId = StringField(validators=[DataRequired(message="账号不可为空"),
                                     length(max=32, message="账号超过限定长度")])
    questionnaireId = IntegerField(validators=[DataRequired(message="问卷编号不能为空")])


class CompletionForm(BaseForm):
    userId = StringField(validators=[DataRequired(message="账号不可为空"),
                                     length(max=32, message="账号超过限定长度")])
    questionnaireId = IntegerField(validators=[DataRequired(message="问卷编号不能为空")])
    questionId = IntegerField(validators=[DataRequired(message="问题编号不能为空")])
    context = StringField(validators=[DataRequired(message="内容不可为空"), length(max=256, message="内容超过最大长度")])
